<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<title>McuNode物联网云服务</title>
<meta name="keywords" content="mcunode，nodemcu物联网云服务，云串口，Lua物联网，nodemcu在线控制，Lua在线开发"/>
<meta name="description" content="本网提供mcunode，物联网云服务，云串口，Lua物联网，nodemcu在线控制，lua在线开发，nodemcu在线编译"/>
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/css/common.css">
</head>
<body>

<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="/">McuNode</a>
    </div>

    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <div class="navbar-form navbar-left" role="search">
            <div class="form-group">
                <input type="text" class="form-control" id="word" placeholder="You id setting here">
            </div>
            <button type="submit" class="btn btn-success" onclick="go()">连接（Link your device）</button>
            <button type="submit" class="btn btn-success" onclick="goweb()">web穿透（Go to Proxy web）</button>
        </div>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="http://nodemcu.readthedocs.io/en/master/" target="_blank">nodemcu API</a></li>
      </ul>
    </div>
  </div>
</nav>
<br><br><br>
<div class="row clearfix">
<div class="col-md-3 column"></div>
<div class="col-md-6 column">
    <h3>使用McuNode Terminal连接NodeMcu，在线控制和开发：</h3>
    <h5>项目地址：<a href="https://github.com/IoTServ/McuNode">https://github.com/IoTServ/McuNode</a></h5>
    <h5>服务端地址：<a href="https://github.com/IoTServ/McuNode-server">https://github.com/IoTServ/McuNode-server</a></h5>
    <h5>库地址：<a href="https://github.com/IoTServ/McuNode-Lib">https://github.com/IoTServ/McuNode-Lib</a></h5>
<div>init.lua demo例子</div>
<textarea class="code">
local mcunode = require "mcunode"

--url:http://mcunodeserver-ip/proxy/<your-id>/gpio?pin=1&val=0
--return:status=success
mcunode.handle("/gpio",function(req,res)
	local pin = req.getParam("pin")
	local val = req.getParam("val")
	if( pin ~= nil) and (val ~= nil) then
		print("pin: "..pin .." , val: " ..val)
		gpio.mode(pin, gpio.OUTPUT)
		gpio.write(pin, val)
		res.setAttribute("status","success")
	end
	return res
end)
mcunode.handle("/test",function(req,res)
	local name = req.getParam("name")
	res.setAttribute("name",name)
	res.body="wodename"
	return res
end)
--url:http://mcunodeserver-ip/proxy/<your-id>/index.html?name=farry&work=student
mcunode.handle("/index.html",function(req,res)
  local name = req.getParam("name")
  res.setAttribute("name",name)
  local work = req.getParam("work")
  res.setAttribute("work",work)
  res.file = "indextpl.html" --调用模板文件indextpl.html
  return res
end)
mcunode.connect("<id>","<tis-server-ip>","ssid","ssid-password")
</textarea>
<div>indextpl.html 模板文件</div>
<textarea class="code2">
<h1>HELLO Farry</h1>
<h1>HELLO Farry</h1>
<h1>HELLO Farry</h1>
<h1>HELLO Farry</h1>
<h1>HELLO Farry</h1>
<h1>HELLO Farry</h1>
</textarea>
<br><br>
<h4>请输入id（init.lua中设置的id）：</h4>
<input type="text" class="form-control" placeholder="id" id="word2" value="" style="width: 300px">
<button type="submit" class="btn btn-success" onclick="go()">打开设备</button>
</div>
<div class="col-md-3 column">
</div>
</div>

<footer class="footer">
    <p class="footer-content">
        @2016
        <a href="/">McuNode物联网云服务</a>
        -IoT Cloud Service
    </p>
</footer>
<script>
    function go() {
        var word = $("#word").val() || $("#word2").val();
        console.log(word);
        if (word != '') {
            location.href = "/term/" + word;
        }
    }
    function goweb() {
        var word = $("#word").val();
        if (word != '') {
            herf="/proxy/" + word + "/index.html";
            console.log(herf);
            location.href = herf;
        }
    }
</script>
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
</body>
</html>